﻿package core.display {
	
	import base.BaseMc;
	import caurina.transitions.Tweener;
	import core.display.FlowerEffect;
	import core.display.RedFlower;
	import flash.utils.Timer;
	import flash.events.TimerEvent;
	import core.display.FlowerBanner;
	import core.display.Star;
	import core.display.FlowerBgLight;
	import core.events.FlowerAnimationEvent;
	import flash.display.Bitmap;
	import flash.media.Sound;
	
	public class  FlowerAnimation2 extends BaseMc {


		private var card:FlowerEffect = new FlowerEffect();
		private var banner:FlowerBanner = new FlowerBanner();
		//private var flower:RedFlower = new RedFlower();
		private var bgLight:FlowerBgLight = new FlowerBgLight();
		private var star1:Star = new Star();
		private var star2:Star = new Star();
		private var star3:Star = new Star();
		private var bg:AlphaBg = new AlphaBg();
		private var bgSound:Sound = new FlowerBgSound();
        public function FlowerAnimation() {
			
		}
		protected override function onRemove():void {
			super.onRemove();
		}
		protected override function onInit():void {
			super.onInit();
			this.addChild(bg);
			
			star2.scaleX *= 0.9;
			star2.scaleY *= 0.9;
			star3.scaleX *= 0.7;
			star3.scaleY *= 0.7;
			
			star1.x = 1290;
			star1.y = 90;
			star1.visible = false;
			star2.x = 1380;
			star2.y = 360;
			star2.visible = false;
			star3.x = 480;
			star3.y = 340;
			star3.visible = false;
			
			this.addChild(star1);
			this.addChild(star2);
			this.addChild(star3);
			
			bgLight.scaleX *= 4;
			bgLight.scaleY *= 4;
			bgLight.x = (this.stage.stageWidth - bgLight.width) / 2 + 85;
			bgLight.y = 100;
			bgLight.visible = false;
			//this.addChild(bgLight);
			
			card.scaleX = card.scaleX * 1;
			card.scaleY = card.scaleY * 1;
			card.x = (this.stage.stageWidth - card.width) / 2+170;
			card.y = this.stage.stageHeight-400;
			card.alpha = 0.1;
			this.addChild(card);
			
			banner.x = (this.stage.stageWidth - banner.width) / 2 + 40;
			banner.y = this.stage.stageHeight + 20;
			this.addChild(banner);
			Tweener.addTween(card,{y:400,alpha:1,time:1,scaleX:1,scaleY:1,
							 transition: "easeOutBack",onComplete:onAvatarCardComplate});
		}
		public function setBabyName(name:String):void {
			this.card.babyName.text = name;
		}
		public function setAvatar(avarta:Bitmap):void {
			avarta.x = 0;
			avarta.y = 0;
			avarta.width = this.card.avarta.width;
			avarta.height = this.card.avarta.width;
			this.card.avarta.addChild(avarta);
		}
		public function onAvatarCardComplate():void {
			var self = this;
			bgSound.play();
			card.gotoAndPlay(2);
			Tweener.addTween(banner,{delay:0.4,time:1,y:640,transition:"easeOutBack"});
			Tweener.addTween(this,{delay:5,/*alpha:0,time:1,y:150,transition:"line",*/onComplete:onFadeoutComplete});
			star1.visible = true;
			star2.visible = true;
			star3.visible = true;
			bgLight.visible = true;
		}
		 private function onFadeoutComplete():void {
			//Tweener.addTween(this,{alpha:0,time:1,y:150,transition:"line",onComplete:onAnimComplete});
			this.dispatchEvent(new FlowerAnimationEvent(FlowerAnimationEvent.COMPLETE));
			
		}
		private function onAnimComplete():void {
			this.dispatchEvent(new FlowerAnimationEvent(FlowerAnimationEvent.COMPLETE));
			
		}
	}
}
